import Koa from 'koa'
import Router from 'koa-router'
import bodyParser from 'koa-bodyparser'
import KoaStatic from 'koa-static'
import cors from 'koa2-cors'
import logger from 'koa-logger'
import { scheduleCronstyle } from './controllers/schedule'
import './mongodb'
import GraphqlRouter from './router'

// 定期删除多于的简历文件
scheduleCronstyle()

const app = new Koa()

app.use(logger())

const router = new Router()

const port = 8082

app.use(cors())

app.use(bodyParser())

app.use(KoaStatic(__dirname + '/static'))

router.use('', GraphqlRouter.routes())

app.use(router.routes()).use(router.allowedMethods())

app.listen(port)

console.log('GraphQL-demo server listen port: ' + port)
